package ua.org.nuos.sdms.clientgui.client.handlers;

import com.vaadin.ui.ComponentContainer;
import ua.org.nuos.sdms.clientgui.client.context.Messages;
import ua.org.nuos.sdms.clientgui.client.controller.GlobalBoard;
import ua.org.nuos.sdms.clientgui.client.events.BackToSearchGroupEvent;
import ua.org.nuos.sdms.clientgui.client.events.ErrorMessageEvent;
import ua.org.nuos.sdms.clientgui.client.listeners.BackToSearchGroupListener;
import ua.org.nuos.sdms.clientgui.client.view.selectGroup.SearchGroupComponent;
import ua.org.nuos.sdms.clientgui.client.view.selectGroup.SearchResultComponent;
import ua.org.nuos.sdms.clientgui.server.AppProxy;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * Created by IntelliJ IDEA.
 * User: dio
 * Date: 08.03.12
 * Time: 16:26
 * To change this template use File | Settings | File Templates.
 */
public class BackToSearchGroupHandler implements BackToSearchGroupListener {
    @Override
    public void back(BackToSearchGroupEvent event) {
        try {
            ComponentContainer parent = AppProxy.getInstance().getComponentLocator().getContainer(SearchResultComponent.ID);
            parent.removeAllComponents();
            parent.addComponent(new SearchGroupComponent());
        } catch (Exception e) {
            Logger.getAnonymousLogger().log(Level.WARNING, "Cant back to group search", e);
            AppProxy.getInstance().getController(GlobalBoard.ID).fire(new ErrorMessageEvent(Messages.ACTION_ERROR));
        }
    }
}
